package xcmg.device.dao.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import xcmg.device.dao.entity.company.CompanyDealerDO;
import xcmg.device.dao.entity.company.CompanyDealerSelectedDO;
import xcmg.device.dao.entity.company.CompanyInfoDO;
import xcmg.device.dao.entity.company.DealerVehicleDO;
import xcmg.device.service.vo.basic.AuthConditionVO;
import xcmg.device.service.vo.company.CompanyDealerVO;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface CompanyDealerMapper {
    int deleteByPrimaryKey(Long id);

    int insertWithPK(CompanyDealerDO companyDealerDO);

    int merge(CompanyDealerDO companyDealerDO);

    CompanyDealerDO item(Long id);

    int update(CompanyDealerDO companyDealerDO);

    List<CompanyDealerDO> list4Gc(CompanyDealerVO companyDealerVO);

    List<CompanyDealerDO> list(CompanyDealerVO companyDealerVO);

    List<DealerVehicleDO> saleBillDealerList(@Param("orgId") String orgId, @Param("companyName") String companyName);

    List<CompanyDealerDO> listByCurrentId(CompanyDealerVO companyDealerVO);

    List<CompanyDealerDO> listBySupplierId(CompanyDealerVO companyDealerVO);

    CompanyDealerDO itemByOrgId(@Param("orgId") String orgId, @Param("dealerOrgId") String dealerOrgId);

    CompanyDealerDO itemByDealerCode(@Param("orgId") String orgId, @Param("dealerCode") String dealerCode);

    List<String> listOrgIdByCode(@Param("code") String code, @Param("orgId") String orgId);

    Integer dealerCodeCount(CompanyDealerDO companyDealerDO);

    Integer nameCount(CompanyDealerDO companyDealerDO);

    Integer checkPendingCount(@Param("orgId") String orgId);

    /**
     * @param platOrgId   String 平台orgId（审核成功之后生成的ID）
     * @param orgId       String 企业关系中上游企业ID（邀请方）
     * @param dealerOrgId String 企业关系中下游企业ID（被邀请方）
     * @return int
     */
    int boundDealer(@Param("platOrgId") String platOrgId, @Param("orgId") String orgId, @Param("dealerOrgId") String dealerOrgId);

    /**
     * 更改下游企业在平台状态（1未邀请，2已邀请，3待审核，4审核拒绝，5审核通过）
     *
     * @param orgId       String 上游企业ID
     * @param dealerOrgId String 下游企业ID
     * @param applyStatus Integer 状态
     * @return int
     */
    int updateApplyStatus(@Param("orgId") String orgId, @Param("dealerOrgId") String dealerOrgId, @Param("applyStatus") Integer applyStatus);

    /**
     * 根据客户分类查询客户数量
     *
     * @param typeId Long
     * @return int
     */
    Integer countCompanyByType(@Param("typeId") Long typeId);

    List<CompanyDealerDO> findByPriceGroup(@Param("orgId") String orgId, @Param("priceGroup") String priceGroup);

    int updateTotalLimit(@Param("totalLimit") BigDecimal totalLimit, @Param("id") Long id);

    int updateEnableLimit(@Param("enableLimit") Integer enableLimit, @Param("ids") List<Long> ids);

    List<String> findDealerOrgIds(@Param("platOrgId") String platOrgId);

    int countDealerByInvitationCode(@Param("orgId") String orgId, @Param("dealerOrgId") String dealerOrgId);

    int findDealerOrgId(@Param("platOrgId") String platOrgId, @Param("dealerOrgId") String dealerOrgId);

    List<CompanyDealerDO> listForPriceScheme(CompanyDealerVO companyDealerVO);

    /**
     * 根据名称模糊搜索出所有匹配的全称
     *
     * @param shortName
     * @return
     */
    List<String> listFullNamesByShortName(@Param("orgId") String orgId, @Param("shortName") String shortName);

    CompanyDealerDO getDealer(@Param("orgId") String orgId, @Param("dealerOrgId") String dealerOrgId);

    CompanyDealerDO getDealerByPlatOrgId(@Param("orgId") String orgId, @Param("platOrgId") String platOrgId);

    CompanyDealerDO getDealerByOrgIdCompanyName(@Param("orgId") String orgId, @Param("companyName") String companyName);

    List<CompanyDealerDO> platformAgentByOrgId(@Param("orgId") String orgId, @Param("companyName") String companyName);

    List<CompanyDealerDO> getRegularAgent(CompanyDealerVO companyDealerVO);

    List<CompanyDealerDO> listByOrgId(@Param("orgId") String orgId);

    CompanyDealerDO get4Import(@Param("orgId") String orgId, @Param("companyName") String companyName, @Param("dealerCode") String dealerCode);

    //根据orgId加dealerCrmCode查询
    CompanyDealerDO selectByOrgIdAndDealerCrmCode(@Param("orgId") String orgId, @Param("dealerCrmCode") String dealerCrmCode);

    //根据orgId加dealerCrmCode软删除
    void softDeleteByOrgIdAndDealerCrmCode(@Param("orgId") String orgId, @Param("dealerCrmCode") String dealerCrmCode);

    void softDeleteById(@Param("id") Long id);

    List<CompanyDealerSelectedDO> getOneProxyList(AuthConditionVO condition);

    List<CompanyInfoDO> getOemInfos(String orgId);

    Integer countByOrgIdAndPlatOrgId(@Param("orgId") String orgId, @Param("platOrgId") String platOrgId);

    //dealerOrgId到客户表查询，使用company_dealer表的id,dealer_org_id,plat_org_id 同时匹配，根据创建时间和id倒叙排序
    List<CompanyDealerDO> selectByDealerOrgId(@Param("dealerOrgId") String dealerOrgId, @Param("orgId") String orgId);

    CompanyDealerDO itemByPlatOrgId(@Param("platOrgId") String platOrgId);

    List<CompanyDealerDO> querySimpleListByVo(@Param("wrap") CompanyDealerVO vo);

    CompanyDealerDO queryOneByDealerCode(@Param("dealerCode") String dealerCode);

    CompanyDealerDO queryOneByPlatOrgIdAndType(@Param("platOrgId") String platOrgId, @Param("dealerType") Integer dealerType);

    CompanyDealerDO queryOneByPlatOrgIdAndTypes(@Param("platOrgId")String platOrgId,@Param("dealerTypeList")  List<Integer> dealerTypeList);

    List<String> queryAllMarketingCenterCode(@Param("ynOrgId") String ynOrgId);

    List<CompanyDealerDO> queryCompanyDealerDOListByCode(@Param("code") String code, @Param("dealerType") int dealerType);


}
